package chapterSystem.client.interfaceDrawing.activities;

import chapterSystem.client.ChapterSystemService;
import chapterSystem.client.callbacks.WriteSimpleEntityCallback;
import chapterSystem.client.entities.Pair;
import chapterSystem.client.model.entitiesInt.Brother;
import chapterSystem.client.model.entitiesInt.Order;
import chapterSystem.client.model.enums.ActivityType;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.StackLayoutPanel;

/**
 * User: Hasp
 * Date: 22.04.12
 * Time: 15:29
 */
public class EditBattleOrderActivity extends WriteBattleOrderActivity {
    protected EditBattleOrderActivity(final Brother brother, final ActivityType type, Activity callback,
                                      Pair<String, Integer> receiver, Order myOrder) {
        super(brother, type, callback, receiver);
        this.myOrder = myOrder;
        submitArea.setText(myOrder.getText());
    }

    private final Order myOrder;

    @Override
    protected ClickHandler createActivityClickHandler(final StackLayoutPanel workArea) {
        return new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                if (submitArea.getText().trim().length() == 0) {
                    Window.alert("Order text must not be empty!");
                } else {
                    myOrder.setText(submitArea.getText());
                    ChapterSystemService.App.getInstance().editBattleOrderText(
                            myOrder, new WriteSimpleEntityCallback(workArea, callback));
                }
            }
        };
    }
}
